package org.jeecg.modules.xindian.reconciliation.controller;

import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.xindian.reconciliation.controller.req.TrendReqInfo;
import org.jeecg.modules.xindian.reconciliation.controller.rsp.CommonDataStatic;
import org.jeecg.modules.xindian.reconciliation.controller.rsp.RankAndProportionRsp;
import org.jeecg.modules.xindian.reconciliation.controller.rsp.SalemanAndChannelProportionRsp;
import org.jeecg.modules.xindian.reconciliation.controller.rsp.TrendRspInfo;
import org.jeecg.modules.xindian.reconciliation.entity.InsuranceStatistics;
import org.jeecg.modules.xindian.reconciliation.service.IInsuranceStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 数据统计
 * @Author: jeecg-boot
 * @Date:   2023-02-28
 * @Version: V1.0
 */
@Api(tags="数据图表统计")
@RestController
@RequestMapping("/banck/dataStatistics")
@Slf4j
public class DataStatisticsController {

    @Autowired
    private IInsuranceStatisticsService insuranceStatisticsService;
    /**
     * 趋势数据
     * @return
     */
    //@AutoLog(value = "杭州银行资金流水-分页列表查询")
    @ApiOperation(value="趋势数据", notes="趋势数据")
    @PostMapping(value = "/list")
    public Result<TrendRspInfo> trend(@RequestBody TrendReqInfo trendReqInfo){
        processDate(trendReqInfo);
        return Result.ok(insuranceStatisticsService.trend(trendReqInfo));
    }

    /**
     * 地区平台排名及占比数据
     * @return
     */
    //@AutoLog(value = "杭州银行资金流水-分页列表查询")
    @ApiOperation(value="地区平台排名及占比数据", notes="地区平台排名及占比数据")
    @PostMapping(value = "/rankAndProportion")
    public Result<RankAndProportionRsp> rankAndProportion(@RequestBody TrendReqInfo trendReqInfo){
        processDate(trendReqInfo);
        return Result.ok(insuranceStatisticsService.rankAndProportion(trendReqInfo));
    }

    private void processDate(TrendReqInfo  trendReqInfo){
        if(trendReqInfo.getStartDate()!=null){
            trendReqInfo.setStartDate(DateUtil.beginOfDay(trendReqInfo.getStartDate()));
        }
        if(trendReqInfo.getEndDate()!=null){
            trendReqInfo.setEndDate(DateUtil.endOfDay(trendReqInfo.getEndDate()));
        }
    }

    /**
     * 渠道业务员排名及占比数据
     * @return
     */
    //@AutoLog(value = "杭州银行资金流水-分页列表查询")
    @ApiOperation(value="渠道业务员排名及占比数据", notes="渠道业务员排名及占比数据")
    @PostMapping(value = "/salesmanAndChannel")
    public Result<SalemanAndChannelProportionRsp> salesmanAndChannel(@RequestBody TrendReqInfo trendReqInfo){
        processDate(trendReqInfo);
        return Result.ok(insuranceStatisticsService.salesmanAndChannel(trendReqInfo));
    }


    /**
     * 保费占比
     * @return
     */
    //@AutoLog(value = "杭州银行资金流水-分页列表查询")
    @ApiOperation(value="保费占比", notes="保费占比")
    @PostMapping(value = "/premium")
    public Result<List<CommonDataStatic>> premiumRank(@RequestBody TrendReqInfo trendReqInfo){
        processDate(trendReqInfo);
        return Result.ok(insuranceStatisticsService.premiumRank(trendReqInfo));
    }
}
